package com.linpq.road.service;

import com.linpq.road.mapper.RdParsingSerialNumberMapper;
import com.linpq.road.util.SerialNumberGenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class RdParsingSerialNumberService {

    @Autowired
    private RdParsingSerialNumberMapper rdParsingSerialNumberMapper;


    public Map<String, Object> selectPileBySerialNumber(String serialNumber){

        Map<String,Object> map = new HashMap<>();

        //管养单位
        String substring1to4 = serialNumber.substring(0,4);
        String managementUnitName = rdParsingSerialNumberMapper.selectManagementUnitBySerialNumber(substring1to4);
        map.put("management_unit",managementUnitName);

        //高速名称
        String substring5to8 = serialNumber.substring(4,8);
        String highWayName = rdParsingSerialNumberMapper.selectHighwayBySerialNumber(substring5to8);
        map.put("high_speed_road",highWayName);


        //路段信息
        String substring9to12 = serialNumber.substring(8,12);
        Integer integer = Integer.valueOf(substring9to12);
        Map<String, String> roadMap = rdParsingSerialNumberMapper.selectRoadBySerialNumber(integer);
        //roadMap添加进路段map中
        map.putAll(roadMap);


        //上下车道
        String substring13 = serialNumber.substring(12,13);
        map.put("up_or_down",substring13);

        //车道
        String substring14 = serialNumber.substring(13,14);
        String lane = SerialNumberGenUtil.lane(substring14);
        map.put("lane",lane);

        //路桩解析
        String substring15to21 = serialNumber.substring(14, 21);
        String parsePileNumber = SerialNumberGenUtil.parsingPileNumber(substring15to21);
        map.put("stake_index",parsePileNumber);

        return map;
    }

}
